﻿package com.codingbros.countdown.view.circle {
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.display.CapsStyle;
	
	/**
	 * ...
	 * @author ...
	 */
	public class Circle extends Sprite {
		private static const CIRCLESTEPS:Number = 360;
		private static const CIRCLESTEPRADIENS:Number = 2 * Math.PI / CIRCLESTEPS;
		
		private static const STARTDEGREES:Number = - 90;
		private static const STARTRADIENS:Number = STARTDEGREES / 360 * 2 * Math.PI;
		
		private var _radius:Number = 100;
		private var _weight:Number = 10;
		private var _color:uint = 0x000000;
		
		private var arch:Shape;
		
		public function Circle() {
			arch = new Shape;
			this.addChild(arch);
		}
		
		public function set radius(value:Number):void 
		{
			_radius = value;
		}
		
		public function set weight(value:Number):void
		{
			_weight = value;
		}
		
		public function  set color(value:uint):void 
		{
			_color = value;
		}
		
		public function update(ratio:Number):void 
		{			
			var startRadiens:Number = 0 + STARTRADIENS;
			var currentRadiens:Number = startRadiens;
			var endRadiens:Number = ratio * 2 * Math.PI + STARTRADIENS;
			
			var lineX:Number = _radius * Math.cos(startRadiens);
			var lineY:Number = _radius * Math.sin(startRadiens);
			
			arch.graphics.clear();
			arch.graphics.lineStyle(_weight, _color, 1, false, "normal", CapsStyle.NONE);
			arch.graphics.moveTo(lineX, lineY);
			while (currentRadiens < endRadiens) 
			{
				currentRadiens += CIRCLESTEPRADIENS;
				
				lineX = _radius * Math.cos(currentRadiens);
				lineY = _radius * Math.sin(currentRadiens);
				
				arch.graphics.lineTo(lineX, lineY);
			}			
			
		}
	}
	
}